package com.crazy.shell.provider.controller;

import com.crazy.shell.provider.entity.Company;
import com.crazy.shell.provider.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * spring-cloud-study
 * 创建人 : creazier.huang
 * 创建日期 : 16/9/21
 * 更新人:
 * 更新时间:
 * 描述:
 */
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private ICompanyService companyService;
    @Autowired
    private DiscoveryClient discoveryClient;


    @GetMapping("/save")
    public Company save(){
        Company company = new Company();
        company.setName("测试001");
        company.setAddr("cess");
        company= companyService.insert(company);

        return company;
    }

    @RequestMapping("/list")
    public List<Company> list(){
        List<Company> list = companyService.findList();
        return list;
    }
    @GetMapping("/instance-info")
    public ServiceInstance showInfo() {
        ServiceInstance localServiceInstance = this.discoveryClient.getLocalServiceInstance();
        return localServiceInstance;
    }
}
